<template>
	<view class="container">
		<block v-if="show">
		<view class="form-container">
			<view class="submit-form-group">
				<view class="form-row">
					<view class="left">支付宝账号</view>
					<input type="text" placeholder="请输入支付宝账号" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.zhifubao" />
				</view>
				<view class="form-row">
					<view class="left">支付宝姓名</view>
					<input type="text" placeholder="请输入支付宝姓名" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.realname" />
				</view>
			</view>
			<button type="default" class="submit-btn" :disabled="btnDisabled" @click="confirm">确认</button>
		</view>
		</block>
	</view>
</template>

<script>
	var validate = require("@/components/validate/validate.js");
	var _this;
	export default {
		data() {
			return {
				btnDisabled:false,
				show:false,
				form: {
					step: 1,
					zhifubao: '',
					realname: '',
				},
			}
		},
		onLoad() {
			_this=this
			this.Submit()
		},
		methods: {
			//获取验证码
			codeChange(text) {
				this.tips = text;
			},
			confirm() {
				this.form.step = 2
				this.Submit()
			},
			async Submit() {
				if (this.form.step == 2) {
					var rule = [{
						// 字段名
						name: 'zhifubao',
						rules: ['require'],
						errorMsg: {
							require: '请输入支付宝账号',
						}
					}, {
						// 字段名
						name: 'realname',
						rules: ['require'],
						errorMsg: {
							require: '请输入支付宝姓名',
						}
					}];
					// 是否全部通过，返回Boolean
					let checked = validate.check(this.form, rule);
					if (!checked) {
						// 获取错误信息
						let err = validate.getError();
						uni.$u.toast(err[0])
						return;
					}
					_this.btnDisabled=true
				}
				const data = await _this.$post('api/set_zfb',this.form)
				if (data.code == 200) {
					this.$u.toast(data.msg)
				} else if (data.code == 10) {
					_this.show=true
					this.mobile = data.data.mobile
					this.form.zhifubao = data.data.zhifubao
					this.form.realname = data.data.realname
				} else {
					this.$u.toast(data.msg)
				}
				setTimeout(()=>{
					_this.btnDisabled=false
				},2000)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/form.scss";
	.container {
		padding: 0;
		.form-container{
			padding: 20rpx 30rpx 0 30rpx;
			.submit-form-group{
				padding: 0 30rpx;
			}
		}
	}
</style>